package com.example.leetcode.stack_deque;

import java.util.Stack;

/**
 * 两个栈实现队列
 */
public class TwoStackConvertDeque {

    public static void main(String[] args) {
        TwoStackConvertDeque twoStackConvertDeque = new TwoStackConvertDeque();

        twoStackConvertDeque.push(2);
        twoStackConvertDeque.push(3);
        twoStackConvertDeque.push(1);

        int pop1 = twoStackConvertDeque.pop();
        int pop2 = twoStackConvertDeque.pop();
        int pop3 = twoStackConvertDeque.pop();
        System.out.println();
    }

    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();

    public void push(int node) {
        stack1.add(node);
    }

    public int pop() {
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()) {
                Integer pop = stack1.pop();
                stack2.add(pop);
            }
        }

        return stack2.pop();
    }
}
